<template>
  <div class="app-container" v-loading="loading">
    <el-form :model="codeForm" :rules="rules" ref="codeForm" label-width="80px">

      <el-form-item label="授权码" prop="code">
        <!--<el-col :xs="12" :sm="12" :md="12" :lg="12"  :xl="12">-->
        <el-input
          type="textarea"
          rows="4"
          placeholder="请输入内容"
          v-model="codeForm.code"
          maxlength="96"
          show-word-limit
        >
        </el-input>
        <!--</el-col>-->

      </el-form-item>

      <el-form-item>
        <el-button @click="resetForm">清空</el-button>
        <el-button @click="importlicense" type="primary">导入</el-button>
      </el-form-item>
    </el-form>

  </div>
</template>

<script>
  export default {
    name: "importAuthorizationCode",
    data:function() {
      var checkId = (rule, value, callback) => {
        console.log(value);
        var reg=/^[0-9A-Za-z]{96}$/
        if(value===""){
          callback(new Error('请输入授权码'));
        }else if (!reg.test(value)) {
          callback(new Error('英文 数字，长度96位'));
        }else {
          callback();
        }
      };
      return {
        text: '',
        codeForm:{
          code: '',
        },
        loading:false,
        rules: {
          code: [
            { validator: checkId, trigger: 'blur' }
          ]
        }
      }
    },
    methods:{
      resetForm() {
        this.$refs['codeForm'].resetFields();
      },
      clearValue:function(){
        this.textarea=""
      },
      importlicense:function () {
        var _this=this
        this.$refs['codeForm'].validate((valid) => {
          if(valid){
            _this.loading=true
            _this.postAjax({
              method:'importlicense',
              params:{
                licensecode:_this.codeForm.code,
              }
            }).then(function (res) {
              console.log(res);
              if(res.result==0){
                _this.tips('导入成功','success')
                // var data=res.params
                // // debugger
                // _this.form.ip=data.ip
                // _this.form.gateway=data.gateway
                // _this.form.mask=data.mask
                // _this.form.dns1=data.dns1
                // _this.form.dns2=data.dns2
              }else {
                _this.tips(res.errorInfo.detail,'error')
              }
            }).catch(function (err) {
              console.log(err);
            }).finally(function (fn) {
              _this.loading=false
              console.log(fn);
            })
          }else{
            return false
          }

        })
      }
    }
  }
</script>

<style scoped>

</style>
